package com.nightpiter.controller.algorithms;

import com.nightpiter.model.objects.Transfer;
import com.nightpiter.model.objects.Transition;

/**
 * Edge class for Dijkstra's Algorithm
 * 
 * Package protected
 * 
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 */
class Edge extends Way implements Cloneable{
	/**
	 * the transition which is represented by this Edge
	 */
	private Transition transition;

	/**
	 * the starting vertex
	 */
	Vertex fromVertex;

	/**
	 * the ending vertex
	 */
	Vertex toVertex;

	/**
	 * public constructor
	 * 
	 * @param transition
	 *            the transition which is represented by this Edge
	 * @param fromVertex
	 *            the starting vertex
	 * @param toVertex
	 *            the ending vertex
	 */
	public Edge(Transition transition, Vertex fromVertex, Vertex toVertex) {
		this.transition = transition;
		this.fromVertex = fromVertex;
		this.toVertex = toVertex;
		if (transition instanceof Transfer) {
			super.set(0, 0, transition.getTime(), 1);
		} else {
			// if instance of Tunnel
			super.set(transition.getTime(), 1, 0, 0);
		}
		fromVertex.addEdge(this);
	}

	/**
	 * @return the transition
	 */
	public Transition getTransition() {
		return transition;
	}

	/**
	 * @return the fromVertex
	 */
	public Vertex getFromVertex() {
		return fromVertex;
	}

	/**
	 * @return the toVertex
	 */
	public Vertex getToVertex() {
		return toVertex;
	}

	public Edge getClone() {
		Edge clonedEdge = null;
		try {
			clonedEdge = (Edge) this.clone();
		} catch (CloneNotSupportedException e) {
		}
		return clonedEdge;
	}
	
}
